<?php

namespace app\index\controller;

use think\Controller;
use think\Request;

class Base extends Controller {

    protected $userInfo;
    protected $userId;
    protected $token;

    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $token = getHeader('Token', '');
        if (empty($token)) {
            $res['success'] = false;
            $res['desc'] = '登录态失效';
            $res['errorcode'] = '-1';
            echo json_encode($res);
            exit;
        }
        $info = \think\Cache::get($token);
        if(empty($info)){
            $res['success'] = false;
            $res['desc'] = '登录态失效';
            $res['errorcode'] = '-1';
            echo json_encode($res);
            exit;
        }
        $this->token = $token;
        $this->userInfo = $info;
        $this->userId = $info['id'];
    }
}